import Vue from 'vue';
import Cookies from 'js-cookie';
import Base64 from 'assets/js/base64.js';
let verifyPasswd = function(passwd) {
    let error_info = '';
    if(!passwd || passwd.length < 8 || passwd.length > 20) {
        error_info = '密码长度为8-20位';
    }else{
        if(passwd.indexOf(' ') > -1) {
            error_info = '密码格式错误，不能含空格';
        }else if(parseInt(passwd) == passwd) {
            error_info = '密码不能为纯数字';
        }
    }
    return error_info;
};
let verifyPhone = function(phone) {
    let err_info = '';
    if (!/^(0|86|17951)?(19[0-9]|16[0-9]|13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/.test(phone)) {
        err_info = '手机号格式错误'
    }
    return err_info;
};
let verifyMailbox = function(mail_box) {
    let error_info = '';
    if (!/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(mail_box)) {
        error_info = '邮箱格式错误';
    }
    return error_info;
};
let exportExcel = function(data, name = 'sheet.xlsx') {
    let blob = new Blob([data], {type: 'vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'});
    let downloadElement = document.createElement('a');
    let href = window.URL.createObjectURL(blob);
    downloadElement.href = href;
    downloadElement.download = name;
    document.body.appendChild(downloadElement);
    downloadElement.click();
    document.body.removeChild(downloadElement);
    window.URL.revokeObjectURL(href);
};
export {verifyPasswd, verifyPhone, verifyMailbox, exportExcel};